package com.learn.netty.bio.multithread;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class BioServer {

    private static  final int PORT = 8081;

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        Socket socket;

        try {
            serverSocket = new ServerSocket(PORT);
            PrintUtils.printLog("start accept port: " + PORT);

            while (true) {
                socket = serverSocket.accept();
                new Thread(new SocketHandler(socket), "socket-handler-thread").start();
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (serverSocket != null) serverSocket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
